/**
 * Created by momomo on 2017/3/20.
 */
$(".addcar").click(function(event){
    var offset = $("#end").offset();
    var offset2= $("#detailPicture").offset();
    var img = $("#detailPicture").find('img').attr('src');
    var flyer = $('<img class="u-flyer" src="'+img+'">');
    flyer.fly({
        start: {
            left: offset2.left+110,
            top: offset2.top-110,
        },
        end: {
            left: offset.left+90, //结束位置（必填）
            top: offset.top+10, //结束位置（必填）
            width: 0, //结束时宽度
            height: 0 //结束时高度
        },
        onEnd: function(){ //结束回调
            $("#msg").show().animate({width: '230px'}, 200).fadeOut(1500); //提示信息
            this.destory(); //移除dom
        }
    });
});


function addProductToCart(productId){
    var num=parseInt($("#productNum").val());
    var id=parseInt(productId);
    productsAddToCartClient.send(id,num,function () {

    });
}
//商品加入购物车
var productsAddToCartClient = {
    send : function(id,num,callBack){
        $.ajax({
            type: 'GET',
            url: '/buyer/shopping_cart_add/',
            data: {
                'id':id,'num':num
            },
            async:false,
            success: function(data){
                if(data == "ok") {
                    callBack();
                }
            },
        });
    }
}

//商品立即购买
var productsBuyNow = {
    send : function(id,num,callBack){
        $.ajax({
            type: 'GET',
            url: '/buyer/shopping_cart_change/',
            data: {
                'id':id,'newNum':num
            },
            async:false,
            success: function(data){
                if(data == "ok") {
                    callBack();
                }
            },
        });
    }
}
function changeNum(flag) {
    var num = parseInt($("#productNum").val());

    if (flag == "minus") {
        if(num<=1){
            alert("宝贝数量必须是大于0");
            return false;
        }
        else {
            num=num-1;
            $("#productNum").val(num);
        }
    }
    else {
        num=num+1;
        $("#productNum").val(num);
    }
}